package com.copa.l1750;

/**
 * @author copa
 * @createDate 2022-12-28 12:06
 * @function 双指针法（参考官方答案）
 */
public class Test2 {

    public int minimumLength(String s) {
        int n = s.length();
        int left = 0;
        int right = n - 1;
        while (left < right && s.charAt(left) == s.charAt(right)) {
            char c = s.charAt(left);
            while (left <= right && c == s.charAt(left)) {
                left++;
            }
            while (left <= right && c == s.charAt(right)) {
                right--;
            }
        }
        return right - left + 1;
    }

    public static void main(String[] args) {
        String s = "bbbbbbbbbbbbbbbbbbb";
        System.out.println(new Test2().minimumLength(s));
    }
}
